<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>我的小组</title>
    @include('common-css')
    <style>
        .input_box {
            width: 100%;
            height: 40px;
            margin-top: 15px;
            margin-bottom: 15px;
            display: flex;
            justify-content: flex-start;
            align-items: center;
        }

        .input_label {
            width: 120px;
            box-sizing: border-box;
        }

        .application-list {
        }

        .phase-tag {
            color: #1890ff;
            border: 1px solid #91d5ff;
            border-radius: 3px;
            background: #e6f7ff;
            font-size: 12px;
            padding: 2px 3px;
        }

        .phase-tag-waiting {
            color: #fa8c16;
            border: 1px solid #fa8c16;
            border-radius: 3px;
            font-size: 12px;
            padding: 2px 3px;
        }

        .ant-table-tbody > tr > td, .ant-table-thead > tr > th {
            vertical-align: middle;
            line-height: 25px;
        }
        .scoring-modal-sum-div {
            display: flex;
            justify-content: flex-end;
            margin-bottom: 16px;
            font-size: 16px;
        }

        .scoring-modal-sum-div span {
            color:#52c41a;
        }
    </style>
</head>
<body>
<div id="app">

</div>
</body>
</html>

<script id="appTemplate" type="x-template">
    <a-locale-provider :locale="antdLocale">
        <div class="container">
            @include('home.header')

            <main>
                <div class="common_container">

                    @include('review.aside', ['selectedItem' => 'review'])

                    <div class="common_content">
                        <div class="common_box">

                            <a-table class="application-list"
                                     rowKey="id"
                                     :columns="applicationListColumns"
                                     :dataSource="applications"
                            >
                            <span slot="award_name" slot-scope="text, record">
                                @{{ findAwardInfoById(record.award_id).name }}
                            </span>
                                <span slot="applicant" slot-scope="text, record">
                                @{{ record.applicant_name }}
                                <a-popover :title="record.applicant_name + '的联系方式'">
                                    <template slot="content">
                                        <table>
                                            <tr>
                                                <td width="30"><a-icon type="phone"/></td>
                                                <td>@{{ record.applicant_tel }}</td>
                                            </tr>
                                            <tr>
                                                <td><a-icon type="mail"/></td>
                                                <td>@{{ record.applicant_email }}</td>
                                            </tr>
                                        </table>
                                    </template>
                                    <a style="font-size: 12px;" href="">联系方式</a>
                                </a-popover>
                                <br/>
                                @{{ record.applicant_org_name }}
                            </span>
                                <span slot="application_form" slot-scope="text, record">
                                <a :href="'/home/fill-form?id=' + record.id" target="_blank">
                                    <span>查看</span>
                                </a>
                            </span>
                                <span slot="status" slot-scope="text, record">
                                    <template v-if="record.is_submitted == 1">
                                        <span class="phase-tag">已提交评分</span>
                                        <div>分数：@{{ record.score }}</div>
                                    </template>
                                    <template v-else-if="record.expert_id">
                                        <span class="phase-tag-waiting">已评分, 待提交</span>
                                        <div>分数：@{{ record.score }}<a style="margin-left:16px"
                                                                      @click="showEditScoreFormModal(record)">修改</a></div>
                                    </template>
                                    <template v-else>
                                        <span class="phase-tag-waiting">未评分</span>
                                    </template>
                            </span>
                                <span slot="todo" slot-scope="text, record">
                                    <span v-if="record.is_submitted == 1">已完成所有操作</span>
                                    <span class="orange" v-else-if="record.expert_id">可修改评分，确认后可提交</span>
                                    <span class="orange" v-else>@{{ record.status_info.reviewer_todo }}</span>
                                </span>
                                <span slot="operations" slot-scope="text, record">
                                        <span v-if="record.is_submitted == 1">-</span>
                                        <a-button v-else-if="record.expert_id" type="primary" size="small"
                                                  @click="submitReview(record)">提交评分</a-button>
                                        <a-button v-else type="primary" size="small"
                                                  @click="showAddScoreFormModal(record.id, record.award_id)">评分</a-button>
                            </span>
                            </a-table>

                        </div>
                    </div>
                </div>
            </main>
        </div>
    </a-locale-provider>
</script>

@include('common-js')

<script>
    const applicationListColumns = [
        {
            width: 40,
            title: '序号',
            dataIndex: 'num'
        }, {
            width: 80,
            title: '奖项',
            dataIndex: 'award_name',
            scopedSlots: {
                customRender: 'award_name'
            }
        }, {
            width: 150,
            title: '申报者',
            dataIndex: 'applicant',
            scopedSlots: {
                customRender: 'applicant'
            }
        }, {
            width: 80,
            title: '申报书',
            dataIndex: 'application_form',
            scopedSlots: {
                customRender: 'application_form'
            }
        }, {
            width: 100,
            title: '评分状态',
            dataIndex: 'status',
            scopedSlots: {
                customRender: 'status'
            }
        }, {
            width: 100,
            title: '待办事项',
            dataIndex: 'nominator_todo',
            scopedSlots: {
                customRender: 'todo'
            }
        }, {
            width: 120,
            title: '操作',
            key: 'operations',
            scopedSlots: {
                customRender: 'operations'
            }
        }];
    const scoreTableListColumns = [
        {
            width: 100,
            title: '评价指标',
            dataIndex: 'evaluation_index',
            scopedSlots: {
                customRender: 'evaluation_index'
            }
        }, {
            width: 330,
            title: '指标含义',
            dataIndex: 'evaluation_index_meaning',
            scopedSlots: {
                customRender: 'evaluation_index_meaning'
            }
        }, {
            width: 460,
            title: '评分方法及标准',
            dataIndex: 'method_of_marking',
            scopedSlots: {
                customRender: 'method_of_marking'
            }
        }, {
            width: 60,
            title: '标准分',
            dataIndex: 'standard_score',
            scopedSlots: {
                customRender: 'standard_score'
            }
        }, {
            width: 60,
            title: '实得分',
            dataIndex: 'real_score',
            scopedSlots: {
                customRender: 'real_score'
            }
        }, {
            width: 90,
            title: '备注',
            dataIndex: 'remarks',
            scopedSlots: {
                customRender: 'remarks'
            }
        }];
    var awardsInfo = {!! json_encode(array_values(config('vars.awards')), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) !!};
    var applications = {!! json_encode($groupScoreDetailsInfo, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) !!};
    var expertId = {!! $user->id !!}
    var groupId = '{!! $group_id !!}'
    function processApplicationsData(applications) {
        var n = 1
        applications.forEach(item => {
            item.num = n
            n += 1
        })
    }

    processApplicationsData(applications)

    Vue.prototype.$axios = axios
    var app = new Vue({
        el: '#app',
        template: '#appTemplate',
        data: {
            defaultSelectedKeys: [groupId],
            expertId: expertId,
            applications: applications,
            submittingApplication: false,
            awardsInfo: awardsInfo,
            applicationListColumns: applicationListColumns,
            changePasswordDialogVisible: false,
            passwordInfo: {
                password: '',
                passwordConfirm: ''
            },
            antdLocale: antd.locales.zh_CN,
            progressScoreFormInfo: [
                {
                    key: '1',
                    evaluation_index: '技术创新性',
                    evaluation_index_meaning: '指成果在关键技术、系统综合集成的创新程度具有自主知识产权在总体技术中所占比（重点查验专利证书）',
                    method_of_marking: '1、技术创新程度显著 20-30<br>2、技术创新程度较大 10-20<br>3、技术创新程度一般 5-10<br>4、技术创新程度较小 0-5',
                    standard_score: 30,
                    real_score: '',
                    remarks: ''
                },
                {
                    key: '2',
                    evaluation_index: '总体技术含量',
                    evaluation_index_meaning: '指成果的主要性能参数, 技术经济指标和总体技术水平与国内外同类项目最高水平比较的程度（以提供的评价证明材料为准）',
                    method_of_marking: '1、技术含量很高 , 达到国际领先水平 25-30<br>2、技术含量高, 达到国际先进水平 20-25<br>3、技术含量较高, 达到国内领先水平 15-20<br>4、技术含量一般, 达到国内先进水平 10-15',
                    standard_score: 30,
                    real_score: '',
                    remarks: ''
                },
                {
                    key: '3',
                    evaluation_index: '经济效益',
                    evaluation_index_meaning: '指成果在应用后的直接经济效益, 包括主要完成单位已经通过技术转让、增收节支、提高效益、降低成本获得的新增利润、税收的金额及他人由于使用该技术而产生的经济收益（以提供的证明材料为准）',
                    method_of_marking: '1、年创收或节约成本500万元以上 10-15<br>2、年创收或节约成本100到500万元 5-10<br>3、年创收或节约成本100万元以下 0-5',
                    standard_score: 15,
                    real_score: '',
                    remarks: ''
                },
                {
                    key: '4',
                    evaluation_index: '社会效益/对相关领域技术进步的推动作用',
                    evaluation_index_meaning: '指成果在促进技术跨越, 推动相关产业结构优化升级, 产品更新换代等方面的作用',
                    method_of_marking: '1、实现重大技术跨越, 对行业技术进步作用显著 10-15<br>2、技术进步明显, 对行业技术进步作用明显 5-10<br>3、技术进步不明显, 对行业技术进步作用一般 0-5',
                    standard_score: 15,
                    real_score: '',
                    remarks: ''
                },
                {
                    key: '5',
                    evaluation_index: '社会效益/节能环保',
                    evaluation_index_meaning: '指成果在工程建设领域推广后, 对社会生活、生态、环境的影响',
                    method_of_marking: '1、与同类技术比较节能作用显著, 推广后有利于保持生态平衡和环境保护 10<br>2、与同类技术比较节能作用明显, 推广后对环境无影响 8<br>3、与同类技术比较具有一定的节能作用, 推广后对环境影响轻微 5<br>4、推广后对环境影响较大,不予评审',
                    standard_score: 10,
                    real_score: '',
                    remarks: ''
                },
            ],
            talentScoreFormInfo: [
                {
                    key: '1',
                    evaluation_index: '技术创新性',
                    evaluation_index_meaning: '指成果在关键技术、系统综合集成的创新程度具有自主知识产权在总体技术中所占比（重点查验专利证书）',
                    method_of_marking: '1、技术创新程度显著 20-30<br>2、技术创新程度较大 10-20<br>3、技术创新程度一般 5-10<br>4、技术创新程度较小 0-5',
                    standard_score: 30,
                    real_score: '',
                    remarks: ''
                },
                {
                    key: '2',
                    evaluation_index: '总体技术含量',
                    evaluation_index_meaning: '指成果的主要性能参数, 技术经济指标和总体技术水平与国内外同类项目最高水平比较的程度（以提供的评价证明材料为准）',
                    method_of_marking: '1、技术含量很高 , 达到国际领先水平 25-30<br>2、技术含量高, 达到国际先进水平 20-25<br>3、技术含量较高, 达到国内领先水平 15-20<br>4、技术含量一般, 达到国内先进水平 10-15',
                    standard_score: 30,
                    real_score: '',
                    remarks: ''
                },
                {
                    key: '3',
                    evaluation_index: '经济效益',
                    evaluation_index_meaning: '指成果在应用后的直接经济效益, 包括主要完成单位已经通过技术转让、增收节支、提高效益、降低成本获得的新增利润、税收的金额及他人由于使用该技术而产生的经济收益（以提供的证明材料为准）',
                    method_of_marking: '1、年创收或节约成本500万元以上 10-15<br>2、年创收或节约成本100到500万元 5-10<br>3、年创收或节约成本100万元以下 0-5',
                    standard_score: 15,
                    real_score: '',
                    remarks: ''
                },
                {
                    key: '4',
                    evaluation_index: '社会效益/对相关领域技术进步的推动作用',
                    evaluation_index_meaning: '指成果在促进技术跨越, 推动相关产业结构优化升级, 产品更新换代等方面的作用',
                    method_of_marking: '1、实现重大技术跨越, 对行业技术进步作用显著 10-15<br>2、技术进步明显, 对行业技术进步作用明显 5-10<br>3、技术进步不明显, 对行业技术进步作用一般 0-5',
                    standard_score: 15,
                    real_score: '',
                    remarks: ''
                },
                {
                    key: '5',
                    evaluation_index: '社会效益/节能环保',
                    evaluation_index_meaning: '指成果在工程建设领域推广后, 对社会生活、生态、环境的影响',
                    method_of_marking: '1、与同类技术比较节能作用显著, 推广后有利于保持生态平衡和环境保护 10<br>2、与同类技术比较节能作用明显, 推广后对环境无影响 8<br>3、与同类技术比较具有一定的节能作用, 推广后对环境影响轻微 5<br>4、推广后对环境影响较大,不予评审',
                    standard_score: 10,
                    real_score: '',
                    remarks: ''
                },
            ],
            scoringFormInfo: {
                id: '',
                award_id: '',
                award_type_id: '',
                scoreDialogVisible: false,
                scoreTableListColumns: scoreTableListColumns,
                formData: [],
                score: 0,
                show_type: '',
            }
        },
        computed: {
            now_score: {
                get: function () {
                    let score = 0
                    this.scoringFormInfo.formData.forEach( item => {
                        console.log(item.real_score)
                        let tmp = item.real_score == '' || item.real_score == undefined ? 0 : parseFloat(item.real_score)
                        score += tmp
                    })
                    return score
                },
                set: function () {
                    return 0
                }
            },
        },
        mounted() {
        },
        methods: {
            submitReview(record) {
                let _this = this
                _this.$confirm({
                    title: '确认要提交评分吗？',
                    content: '提交评分后不可再修改',
                    ookText: '确认',
                    cancelText: '取消',
                    onOk() {
                        megLoading('正在提交...')
                        let url = '/api/db/update'
                        let records = [
                            {
                                id: record.relation_id,
                                is_submitted: 1
                            }
                        ]
                        axios.post(url, {
                            model: 'ExpertScoringApplicationRelations',
                            records
                        }).then(res => {
                            megDestroy()
                            if (res.data.ok) {
                                megSuccess('操作成功')
                                history.go(0)
                            } else {
                                megError(res.data.message)
                                return false
                            }
                        })
                    }
                })
            },
            closeScoreFromModel() {
                this.scoringFormInfo.formData = []
                this.scoringFormInfo.award_type_id = ''
                this.scoringFormInfo.award__id = ''
                this.scoringFormInfo.show_type = ''
                this.scoringFormInfo.id = ''
                this.now_score = 0
                this.scoringFormInfo.scoreDialogVisible = false
            },
            submitScoreFormModel() {
                let _this = this
                let {formData, award_id, score, show_type, id, award_type_id} = this.scoringFormInfo
                let hasError = false
                let errorMeg = ''
                formData.forEach(item => {
                    if (item.real_score == '') {
                        hasError = true
                        errorMeg = item.evaluation_index + '未填写分数'
                        return false
                    }
                    score += item.real_score
                })
                if (hasError) {
                    megError(errorMeg)
                    errorMeg = ''
                    hasError = false
                    return false
                }
                megLoading('正在提交...')
                let url = '/api/db/create'
                let records = [
                    {
                        expert_id: _this.expertId,
                        application_id: award_id,
                        form_data: JSON.stringify(formData),
                        score
                    }
                ]
                if (show_type == 'edit') {
                    url = '/api/db/update'
                    records = [
                        {
                            id,
                            expert_id: _this.expertId,
                            application_id: award_id,
                            form_data: JSON.stringify(formData),
                            score
                        }
                    ]
                }
                console.log('records', records)
                axios.post(url, {
                    model: 'ExpertScoringApplicationRelations',
                    records
                }).then(res => {
                    megDestroy()
                    if (res.data.ok) {
                        megSuccess('操作成功')
                        history.go(0)
                    } else {
                        megError(res.data.message)
                        return false
                    }
                })
            },
            showEditScoreFormModal(record) {
                this.scoringFormInfo.formData = JSON.parse(record.form_data)
                this.scoringFormInfo.award_type_id = record.award_id
                this.scoringFormInfo.award_id = record.id
                this.scoringFormInfo.show_type = 'edit'
                this.now_score = record.score
                this.scoringFormInfo.id = record.relation_id
                this.scoringFormInfo.scoreDialogVisible = true
            },
            showAddScoreFormModal(award_id, award_type_id) {
                this.scoringFormInfo.award_id = award_id
                if (award_type_id == 1) {
                    this.scoringFormInfo.formData = JSON.parse(JSON.stringify(this.progressScoreFormInfo))
                } else {
                    this.scoringFormInfo.formData = JSON.parse(JSON.stringify(this.talentScoreFormInfo))
                }
                this.scoringFormInfo.award_type_id = award_type_id
                this.scoringFormInfo.show_type = 'create'
                this.scoringFormInfo.scoreDialogVisible = true
            },
            findAwardInfoById(id) {
                return this.awardsInfo.filter(item => {
                    return item.id == id
                })[0]
            },
            handleHeaderDropdownItemClick: handleHeaderDropdownItemClick,
            handleChangePasswordOk: handleChangePassword
        }
    })
</script>